package com.zcoj.mail.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcoj.mail.mapper.MailLogMapper;
import com.zcoj.mail.pojo.MailLog;
import com.zcoj.mail.service.MailLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Service实现
 * @author 剩xia的盛夏
 * @date 2023/03/04 23:39
 */
@Service
public class MailLogServiceImpl implements MailLogService {

    @Autowired
    private MailLogMapper mailLogMapper;

    @Override
    public Integer create(MailLog mailLog) {
        mailLogMapper.insert(mailLog);
        return mailLog.getId();
    }

    @Override
    public void deleteById(Integer id) {
        mailLogMapper.deleteById(id);
    }

    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) return;
        mailLogMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateById(MailLog mailLog) {
        mailLogMapper.updateById(mailLog);
    }

    @Override
    public void updateByIdInBatch(List<MailLog> mailLogs) {
        if (CollectionUtils.isEmpty(mailLogs)) return;
        for (MailLog mailLog: mailLogs) {
            this.updateById(mailLog);
        }
    }

    @Override
    public MailLog findById(Integer id) {
        return mailLogMapper.selectById(id);
    }

    @Override
    public MailLog findOne(MailLog mailLog) {
        Wrapper<MailLog> wrapper = new QueryWrapper<>(mailLog);
        return mailLogMapper.selectOne(wrapper);
    }


    @Override
    public long count(MailLog mailLog) {
        Wrapper<MailLog> wrapper = new QueryWrapper<>(mailLog);
        return mailLogMapper.selectCount(wrapper);
    }
}
